package com.exer;

/**
 * 获取一个字符串在另一个字符串中出现的次数
 */
public class StringDemo2 {

    public static void main(String[] args) {
        String str1 = "ab";
        String str2 = "abbdsalabjldsaabababdsjalj";
        System.out.println(getCount(str1,str2));
    }

    public static int getCount(String superClass, String subClass){
        if(superClass != null && subClass != null && superClass.length() <= subClass.length()){
            int index = 0;
            int count = 0;
            while ((index = subClass.indexOf(superClass,index)) != -1){
                count++;
                index++;
            }
            return count;
        }
        return 0;
    }
}
